package com.frxuexi.mine.view

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Divider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import coil3.compose.AsyncImage
import com.frxuexi.lib_base.BaseTitle
import com.frxuexi.mine.R
import com.frxuexi.mine.entity.LeaveEntity
import com.frxuexi.mine.viewmodel.LeaveViewModel
import com.google.gson.Gson
import com.tencent.mmkv.MMKV

@Composable
fun LeaveDetailPage(navHostController: NavHostController,json:String,vm:LeaveViewModel= hiltViewModel()) {
    var uname by remember {
        mutableStateOf(MMKV.defaultMMKV().decodeString("uname", "未登录").toString())
    }

    val entity = Gson().fromJson(json, LeaveEntity::class.java)
    Column {
        BaseTitle(title = "请假详情", navHostController = navHostController)

        Column(
            Modifier
                .fillMaxSize()
                .padding(horizontal = 20.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
            Text(text = "申报人信息", color = Color.Blue)
            Row(modi) {
                AsyncImage(
                    model = "https://img0.baidu.com/it/u=797474174,3214837072&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1732294800&t=f472f47d1015da000b2194ee3b7a3c4a",
                    contentDescription = "",
                    modifier = Modifier
                        .size(80.dp)
                        .clip(CircleShape),
                    contentScale = ContentScale.Crop
                )
                Text(text = uname)
            }

            Spacer(modifier = Modifier.height(10.dp))
            Text(text = "请假详情", color = Color.Blue)
            Text(text = "请假方式: ${entity.type}")
            Text(text = "开始时间: ${entity.startTime}")
            Text(text = "结束时间: ${entity.endTime}")
            Text(text = "请假原因: ${entity.reason}")
            Spacer(modifier = Modifier.height(10.dp))
            Row(Modifier.padding(horizontal = 20.dp)) {
                Column(horizontalAlignment = Alignment.CenterHorizontally) {
                    AsyncImage(
                        model = "https://img0.baidu.com/it/u=797474174,3214837072&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1732294800&t=f472f47d1015da000b2194ee3b7a3c4a",
                        contentDescription = "",
                        modifier = Modifier
                            .size(40.dp)
                            .clip(CircleShape),
                        contentScale = ContentScale.Crop
                    )
                    Divider(
                        Modifier
                            .width(1.dp)
                            .height(30.dp))
                    var img=if(entity.status=="通过") R.drawable.ic_action_yes else if(entity.status=="拒绝") R.drawable.ic_action_refuse else R.drawable.ic_action_no
                    Image(painter = painterResource(id = img), contentDescription = "", modifier = Modifier
                        .size(40.dp))
                }
                
                Spacer(modifier = Modifier.width(10.dp))
                Column {
                    Text(text = "已提交")
                    Text(text = "提交时间：${entity.createTime}", color = Color.Gray, fontSize = 12.sp)
                    Spacer(modifier = Modifier.height(30.dp))

                    Text(text = entity.status)
                    var time=if(entity.comTime==null) "" else entity.comTime
                    Text(text = "审批时间：${time}", color = Color.Gray, fontSize = 12.sp)
                }

            }
        }
    }
}